package com.iexbuy.ihg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.entity.ChouJiangRecordListObject;
import com.iexbuy.ihg.utils.StringUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

;

public class ChouJiangHistoryListAdapter extends BaseAdapter {

	private List<ChouJiangRecordListObject> datas = new ArrayList<ChouJiangRecordListObject>();
	private Context context;

	public ChouJiangHistoryListAdapter(Context context, List<ChouJiangRecordListObject> datas) {
		super();
		this.context = context;
		if (datas != null) this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int location) {
		return datas.get(location);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ChouJiangRecordListObject vo = (ChouJiangRecordListObject)datas.get(position);

		//0购物品的状态, 是否已经开奖(1：进行中，3：待发货。4：已完成)
		if ("1".equalsIgnoreCase(vo.getStatus())) {
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.fragment_yunguo_list_item, null);
			}
			((TextView) convertView.findViewById(R.id.yungouName)).setText("[第"+vo.getPeriod()+"期] " + vo.getItemName());
			((TextView) convertView.findViewById(R.id.attendanceNo)).setText(vo.getAttendNumber());
			((TextView) convertView.findViewById(R.id.totalRequireNo)).setText(vo.getRequiredNumber());
			((TextView) convertView.findViewById(R.id.balenceNo)).setText(String.valueOf(Integer.valueOf(vo.getRequiredNumber()) - Integer.valueOf(vo.getAttendNumber())));
			((ProgressBar) convertView.findViewById(R.id.yunProgress)).setProgress(new BigDecimal(vo.getAttendNumber()).divide(new BigDecimal(vo.getRequiredNumber()), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).intValue());
			App.bitmapUtils.display((ImageView) convertView.findViewById(R.id.yungouImg), vo.getThumnailUrl());
		} else {
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.fragment_yunguo_list_item_finish, null);
			}
			((TextView) convertView.findViewById(R.id.yungouName)).setText("[第"+vo.getPeriod()+"期] " + vo.getItemName());
			((TextView) convertView.findViewById(R.id.itemTime)).setText("开奖日期：" + vo.getRevealTime());
			((TextView) convertView.findViewById(R.id.luckerName)).setText("幸运儿： " + StringUtil.hideMobileNo(vo.getLuckUserName()));
			App.bitmapUtils.display((ImageView) convertView.findViewById(R.id.yungouImg), vo.getThumnailUrl());

		}

		return convertView;
	}
	
	private Double getMagnitude(String magnitudeStr) {
		Double magnitude = Double.valueOf("0");
		try {
			magnitude = Double.valueOf(magnitudeStr);
		} catch (Exception e) {
		}
		return magnitude;
	}
	
}
